﻿Imports System.ComponentModel
Namespace Console
	''' <summary>
	''' Used to view and present feedback for what's happening in the program.
	''' </summary>
	''' <remarks></remarks>
	Public Class ConsoleFeed
		Implements INotifyPropertyChanged
#Region "Implements"

#Region "Notification"
		Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

		Friend Overridable Sub RaisePropertyChanged(ByVal PropertyName As String)
			Try
				RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
			Catch
			End Try
		End Sub
#End Region

#End Region

#Region "Properties"

		''' <summary>
		''' Represents the Contents Property.
		''' </summary>
		''' <remarks></remarks>
		Private ContentsProperty As New Text.StringBuilder

		''' <summary>
		''' Contains the contents of the console. Bind this to a text box to get a continual console feed.
		''' </summary>
		''' <remarks></remarks>
		Public Property Contents As String
			Get
				Return ContentsProperty.ToString
			End Get
			Set(value As String)
				ContentsProperty.Insert(0, value)
				RaisePropertyChanged("Contents")
			End Set
		End Property




#End Region

#Region "Public Functions"

		''' <summary>
		''' Send a message to the console.
		''' </summary>
		''' <param name="message">The message to pass to the console.</param>
		''' <param name="Timestamp">Indicates whether a timestamp should be added to the console message. Defaults to true.</param>
		''' <remarks></remarks>
		Public Sub SendMessage(ByVal message As String, Optional ex As Exception = Nothing, Optional Timestamp As Boolean = True)
			Try
				If Timestamp = True Then
					Dim stamp As String = Now.ToShortDateString & " " & Now.ToShortTimeString & " >>> "
					message = message.Insert(0, stamp)
					message += vbCrLf
				Else
					message += vbCrLf
				End If
				If My.Settings.DebugVerbose AndAlso ex IsNot Nothing Then
					message += "#####VERBOSE MESSAGE#####" & vbCrLf & "The accompanying exception is:" & vbCrLf & ex.ToString & vbCrLf & "##########" & vbCrLf
				End If
				Contents = message
			Catch
			End Try
		End Sub


#End Region

	End Class
End Namespace